﻿using Autofac;
using B.MES.Customer.Infrastructure.IRepository;
using B.MES.Customer.Infrastructure.Repository;
using System.Reflection;

namespace B.MES.Customer.Read.WebApi.Module
{
    /// <summary>
    /// 自定义AutoFac方法
    /// </summary>
    public class RBACModule : Autofac.Module
    {
        /// <summary> 
        /// 重写Load方法 
        /// </summary> 
        /// <param name="builder">容器</param> 
        protected override void Load(ContainerBuilder builder)
        {
            // 加载业务逻辑相关的类库
            var applicationAssembly = Assembly.Load("B.MES.Customer.Application");
            var infrastructureAssembly = Assembly.Load("B.MES.Customer.Infrastructure");

            // 注册应用层(Application)中以“Application”结尾的类
            builder.RegisterAssemblyTypes(applicationAssembly)
                   .Where(t => t.Name.EndsWith("Application"))
                   .AsImplementedInterfaces();

            // 注册基础设施(Infrastructure)中以“Repository”结尾的类
            builder.RegisterAssemblyTypes(infrastructureAssembly)
                   .Where(t => t.Name.EndsWith("Repository"))
                   .AsImplementedInterfaces();
          
            // 调用基类的Load方法
            base.Load(builder);
        }
    }
}
